home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5029 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: sscanf bug??????
  5. Date: 10 Feb 1996 22:21 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <10FEB199622213548@erich.triumf.ca>
  9. References: <4fimvo$82s@fnord.dfw.net>
  10. NNTP-Posting-Host: ftp.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <4fimvo$82s@fnord.dfw.net>, jtmcap@dfw.dfw.net (Jerry Jackson) writes...
  14. >the following is a program compiled using microway ndp c/c++ compiler.
  15. >#include <stdio.h>
  16. >#include <string.h>
  17. >main()
  18. >{
  19. >    char str_1[] = "013196";
  20. >    char str_2[] = "13196";
  21. >    long res_1, res_2;
  22. >    sscanf(str_1,"%d",&res_1);
  23. >    sscanf(str_2,"%d",&res_2);
  24. >    printf("\nres_1 = %d",res_1);
  25. >    printf("\nres_2 = %d",res_2);
  26.  
  27. Borland says that you need to use "%ld" for long ints in both printf() and 
  28. scanf().  If ints and longs are the same size (as on many unix systems, I
  29. believe) "%d" and "%ld" can be used interchangeably, but if they are not the
  30. same (as on MS-DOS) then it _does_ make a difference.
  31.  
  32. >microway says that the leading zero causes sscanf to do an octal 
  33. >conversion on the integer. 
  34.  
  35. Borland indicates you need "%o" to read octal numbers. Reading quiclky through
  36. the description of scanf(), I don't see any indication that a leading 0 will
  37. trigger an octal conversion...
  38.  
  39. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  40. Internet: bennett@triumf.ca         | of one another only when one can be
  41. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  42. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  43. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.